<?php
use yii\helpers\Url;
$this->context->layout = false;
?>
<?php
//使用率
echo $this->render("@app/views/public/useRate.php")
?>
<div id="pick-affected-grid"></div>
<script type="text/x-kendo-template" id="pickAffectedTemplate">
    <input type="text" id="pick-affected-month"  name="month" value="<?=$month?>">
    <a class="k-button k-button-icontext k-grid-excel" style="float:right"><span class="k-icon k-i-excel"></span>导出</a>
</script>
<script>
    var pick_affected_grid = $("#pick-affected-grid"),affectedDepartment;
    $.ajax({
        type: "GET",
        async: false,
        url: "<?=Url::toRoute(['/hr/pick/default/groupdepartment']); ?>",
        dataType: "json",
        success: function (data) {
            affectedDepartment = data;
        }
    });
    $(document).ready(function() {
        pick_affected_grid.kendoGrid({
            dataSource: {
                transport: {
                    read:function (e) {
                        $.ajax({
                            url: "<?=Url::to(['pickaffectedlist']); ?>",
                            data:{month:$("#pick-affected-month").val()},
                            type:"POST",
                            dataType: "json",
                            success:function (redata) {
                                e.success(redata);
                            }
                        })
                    }
                },
                schema: {
                    model: {
                        fields: {
                            created: { field:"created",type:"date"},
                            department_name: { field:"department_name"},
                            group_name: {field:"group_name"},
                            username:{field:"username"},
                            level1_name: {field:"level1_name"},
                            level2_name: {field:"level2_name"},
                            content: {field:"content"},
                            affected_group: {field:"affected_group"},
                            affected_staff: {field:"affected_staff"}
                        }
                    }
                },
                pageSize: 20
            },
            sortable: true,
            filterable: {
                extra: false,
                operators: {
                    string: {
                        contains: "包含",
                        doesnotcontain: "不包含",
                        eq: "等于",
                        neq: "不等于"
                    }
                }
            },
            excel: {
                allPages: true,
                fileName:"績效影響.xlsx",
                filterable: true
            },
            excelExport: function(e) {
            },
            toolbar:kendo.template($("#pickAffectedTemplate").html()),
            pageable:{
                refresh: true,//刷新按钮
                pageSizes: [20, 40, 60, "all"],//每页数量选择
                buttonCount: 5//页码按钮数量
            },
            columns: [
                {
                    field:"created",
                    title: "美国时间" ,
                    format: "{0:MM/dd/yyyy}",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "department_name",
                    title:"部门" ,
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "group_name",
                    title:"组别" ,
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field:"username",
                    title:"發佈人" ,
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "level1_name",
                    title:"LEVEL 1" ,
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field:"level2_name",
                    title:"LEVEL 2" ,
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "content",
                    title:"詳情" ,
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute,
                    width: "26%"
                },
                {
                    field: "affected_group",
                    title:"被影響組" ,
                    headerAttributes: alignCenterAttribute,
                    template:function (e) {
                        if(e.affected_group){
                            return e.affected_group;
                        }
                        var html = "";
                        for (var o in affectedDepartment) {
                            if (affectedDepartment[o].id == e.department_id) {
                                if (affectedDepartment[o].hasChildren){
                                    html = "未選擇";
                                }else{
                                    tml = "無";
                                }
                            }
                        }
                        return html;
                    },
                    attributes: alignCenterAttribute
                },
                {
                    field: "affected_staff",
                    title:"被影響人" ,
                    template:"#: affected_staff #",
                    headerAttributes: alignCenterAttribute,
                    attributes: {style: "text-align: center;word-wrap: break-word;word-break: normal;"}
                }
            ]
        });
        $("#pick-affected-month").kendoDatePicker({
            format: "yyyy-MM",
            depth: "year",
            start: "year",
            culture: "zh-CN",
            change:function(e){
                var _grid = pick_affected_grid.data("kendoGrid");
                _grid.dataSource.read();
                _grid.refresh();
            }
        });
    });
</script>